<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<script src="calendar_beans_v2.0_hide.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery-1.7.2.js" type="text/javascript" charset="utf-8"></script>
<script>
	var loc_no;
	$(document).ready(function() {
		CalAddCss(); // !!제일 상단에 필수!!
		initCal({
			id : "cal3",
			type : "day",
			today : "y",
			icon : "y"
		});
		initCal({
			id : "cal4",
			type : "day",
			today : "y",
			icon : "y"
		});
		
		$("#localSelect").change(function(){			
			loc_no = $(this).val();
			$.ajax({
				type:"post",
				url:"admin.do",
				data:"command=getTheaterListByLocalNo&loc_no="+loc_no,
				dataType:"json",
				success:function(data){
					var select="<select id='theaterSelect' name='theater_no'><option value=defulat>- - - - - -</option>";
					  $.each(data.list,function(indexl,value){
					      select+=" <option value="+value.THEATER_NO+">"+value.THEATER+"</option>";
					     });
						select+="</select>";		
					$("#theaterList").html(select); 
				}
			});// ajax
		});//local change
		$("#theaterSelect").change(function(){
			var theater = $(this).val();
			$("#theater").html(theater);
		});//local change
		$("#movieSelect").change(function(){
			var movie_no = $(this).val();
			$.ajax({
				type:"post",
				url:"admin.do",
				data:"command=getPublicDayByMovieNo&movie_no="+movie_no,
				dataType:"json",
				success:function(data){
					 var day = "<input type='text' readonly='readonly' size='30' value='"+data.pday[0].OPENING_DAY+" ~ "+data.pday[0].ENDING_DAY+"'>";
					$("#public_day").html(day);  
				}
			});// ajax
		});//local change
		$("#regScreeningForm").submit(function(){
			var flag = confirm("등록 하시겠습니까?");
			if(!flag){
				return false;
			}//if				
		});//regScreeningMovieForm

		$(":input:checkbox:[name=allCheck]").click(function(){		
			var flag=$(this).attr("checked");
			$(":input:checkbox:[name=smCheck]").each(function(){
				var subChecked=$(this).attr("checked");
				if(subChecked!=flag){
					$(this).click();
				}
			}) //each
		}); //전체선택
		$("#delChecked").click(function(){
			var arr = [];
			var flag=true;
			var delcheckbox = document.getElementsByName("smCheck");
			for(i=0;i<delcheckbox.length;i++){
				if(delcheckbox[i].checked){
					alert(delcheckbox[i].value);
					arr.push(delcheckbox[i].value);
					flag=false;
				}
			}
			if(flag){
				alert("삭제하실 시간표를 선택하세요."); 
				return false;
			}
			if(confirm('삭제하시겠습니까?')){
				alert(arr.toString());				
				 $.ajax({
					url:"admin.do?command=screeningMovieDel&list="+arr.toString(),
					dataType:"json",
					success:function(js){
						alert("삭제성공 ");
						location.href="admin.do?command=regScreeningMovieForm";
					}
				}); 
			}
		}); // 선택삭제 button click
		
	});		
</script>
<c:choose>
<c:when test="${sessionScope.vo.memberlevelinfoVO.member_level_no !=1}">
<script>
	alert("잘못된 접근입니다!");           
	location.href="mycinema.do?command=home_main";
</script>
</c:when>
<c:when test="${sessionScope.vo.memberlevelinfoVO.member_level_no ==1}">
<form method="post" id="regScreeningForm" action="admin.do">
<input type="hidden" name="command" value="regScreeningMovie">
<font class='title'>Screen Movie 등록</font><hr color="#f5f5f5">
<table cellspacing='0' border='1' width='90%' height='50'>
	<tr align="center" width='300' bgcolor="#f5f5f5">
		<td width='100'>지 역</td>
		<td width='150'>영화관</td>
		<td>영 화</td>
		<td width='160'>상영기간</td>
		<td>개봉일</td>
		<td>종료일</td>
		<td>추 가</td>
	</tr>	
	<tr align="center">
		<td><select id="localSelect" name="loc_no">
				<option>- - - - - -</option>
				<c:forEach items="${requestScope.info.local}" var="local">
					<option value="${local.loc_no}">${local.loc}</option>
				</c:forEach>	
			</select></td>
		<td><span id='theaterList'><select id="theaterSelect" name="theater_no">
				<option>- - - - - -</option>
				<c:forEach items="${requestScope.info.theater}" var="theater">
					<option value="${theater.theater_no}">${theater.theater}</option>
				</c:forEach>	
			</select></span></td>
		<td><select id="movieSelect" name="movie_no">
				<option>- - - - - -</option>
				<c:forEach items="${requestScope.info.movie}" var="movie">
					<option value="${movie.movie_no}">${movie.movie_title}</option>
				</c:forEach>	
			</select></td>
		<td><span id="public_day"></span></td>	
		<td><input type="text" id="cal3" size="13" name="starting_day" readonly="readonly" style='height:19px'></td>
		<td><input type="text" id="cal4" size="13" name="ending_day" readonly="readonly" style='height:19px'></td>
		<td><input type="submit" id="addsm"value="추가"></td>
	</tr>
</table>
</form>
<hr>
<b>screening movie list</b> 
<input type="button" id="delChecked" value="선택 삭제">
<table border='1' cellspacing='0' width='90%'>
	<tr bgcolor="#f5f5f5" align='center'>
		<td width="50"><input type="checkbox" name="allCheck"> 선택</td>
		<td> 지 역 </td>
		<td> 영화관 </td>
		<td> 영화제목 </td>
		<td> 개봉일 </td>
		<td> 종료일 </td>
	</tr>

	<c:forEach items="${requestScope.info.screening_movie_list}" var="list">
	<tr align='center'>
		<td width="50"><input type="checkbox" class='delcheckboxclass' name="smCheck" value="${list.MOVIE_NO},${list.THEATER_NO}"></td>
		<td> ${list.LOC} </td>
		<td>${list.THEATER}</td>
		<td>${list.MOVIE_TITLE}</td>
		<td>${list.STARTING_DAY}</td>
		<td>${list.ENDING_DAY}</td>
	</tr>
	</c:forEach>
</table>
</c:when>
</c:choose>






